﻿Imports ccapps.persistent.CustomerHistory

Public Class ContractHistory
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Session("user") = "" Or Session("user") Is Nothing Then
            Session("message") = "!!Session Timeout!!,Tekrar Giriş Yapmalısınız"
            Response.Clear()
            Response.Status = "302 Object Moved"
            Response.RedirectLocation = "CX_Exception.aspx"
            Response.End()
        End If
        If Not IsPostBack Then
            Dim now As DateTime = DateTime.Now
            Dim month2 As String = ""
            Dim gun2 As String = ""
            Dim flag As Integer = 0
            Dim month As String = ""
            Dim year As String = ""



            TxtDate.Text = now.AddMonths(-1).ToString("dd/MM/yyyy").Replace(".", "/")


            TxtDate2.Text = now.ToString("dd/MM/yyyy").Replace(".", "/")




            Dim bilgiler() As String = TxtDate.Text.Split("/")
            Label26.Text = ""
            For Each satir As String In bilgiler
                Label26.Text += satir
            Next



            Dim bilgiler2() As String = TxtDate2.Text.Split("/")
            Label27.Text = ""
            For Each satir2 As String In bilgiler2
                Label27.Text += satir2
            Next

        End If



    End Sub

    Protected Sub SMSISDN_Click(sender As Object, e As EventArgs) Handles SMSISDN.Click
        Try
            lblcontrol.Text = "0"

            ErrorMes.Text = ""
            confirmTable.Visible = False
            TxtCustcode.Text = ""
            ListBox1.SelectedIndex = -1
            clear()
            If TxtMsisdn.Text.Length = 0 Then
                Me.Page.RegisterStartupScript("javascript", "<script language=""javascript"">alert('MSISDN Alanın Girilmesi Zorunludur.');</script>")
            Else

                If Not TxtMsisdn.Text.Length = 10 Then
                    Me.Page.RegisterStartupScript("javascript", "<script language=""javascript"">alert('MSISDN Alanı 10 Karakter İçermelidir.');</script>")
                Else



                    Dim dt As DataTable = GetCustInfoFromMSISDN(TxtMsisdn.Text)
                    Try
                        If dt.Rows.Count > 0 Then

                            LblCustomer.Text = dt.Rows(0)("NAME").ToString() + "   " + dt.Rows(0)("LASTNAME").ToString() + "   " + dt.Rows(0)("CITY").ToString()
                            LblCsid.Text = dt.Rows(0)("CSID").ToString()
                            LblCustcodeMSısdn.Text = TxtMsisdn.Text
                            confirmTable.Visible = True
                            Dim dthist As DataTable = ContractHistoryAuto(Convert.ToInt32(LblCsid.Text), Label27.Text, Label26.Text)
                            If dthist.Rows.Count > 0 Then
                                emtytable.Visible = False
                                GridView2.Visible = True
                                GridView2.DataSource = dthist
                                GridView2.DataBind()

                            Else
                                emtytable.Visible = True
                                GridView2.Visible = False
                            End If
                        Else
                            ErrorMes.Text = "Girmiş Olduğunuz MSISDN'e Ait Veri Bulunamamıştır"

                        End If

                    Catch ex As Exception

                    End Try

                End If
            End If
        Catch ex As Exception
            ErrorMes.Text = "Girmiş Olduğunuz MSISDN'e Ait Veri Bulunamamıştır"
        End Try
      





    End Sub

    Protected Sub SCustCode_Click(sender As Object, e As EventArgs) Handles SCustCode.Click
        Try
            lblcontrol.Text = "0"
            ErrorMes.Text = ""
            confirmTable.Visible = False
            TxtMsisdn.Text = ""
            ListBox1.SelectedIndex = -1



            clear()
            If TxtCustcode.Text = "" Then
                Me.Page.RegisterStartupScript("javascript", "<script language=""javascript"">alert('CustCode Alanın Girilmesi Zorunludur.');</script>")
            Else

                Dim dt As DataTable = GetCustInfoFromCustcode(TxtCustcode.Text)
                If dt.Rows.Count > 0 Then
                    'Table2.Visible = True
                    LblCustomer.Text = dt.Rows(0)("NAME").ToString() + "   " + dt.Rows(0)("LASTNAME").ToString() + "   " + dt.Rows(0)("CITY").ToString()
                    LblCustcodeMSısdn.Text = TxtCustcode.Text
                    LblCsid.Text = dt.Rows(0)("CSID").ToString()
                    confirmTable.Visible = True
                    Dim dthist As DataTable = ContractHistoryAuto(Convert.ToInt32(LblCsid.Text), Label27.Text, Label26.Text)
                    If dthist.Rows.Count > 0 Then
                        emtytable.Visible = False
                        GridView2.Visible = True
                        GridView2.DataSource = dthist
                        GridView2.DataBind()

                    Else
                        emtytable.Visible = True
                        GridView2.Visible = False
                    End If
                Else
                    ErrorMes.Text = "Girmiş Olduğunuz CUSTCODE'a Ait Veri Bulunamamıştır"

                End If

            End If

        Catch ex As Exception
            ErrorMes.Text = "Girmiş Olduğunuz CUSTCODE'a Ait Veri Bulunamamıştır"
        End Try
       
    End Sub
   



    Protected Sub SCustCode0_Click(sender As Object, e As EventArgs) Handles SCustCode0.Click
        Try
            lblcontrol.Text = "1"


            PrintSearch()
        Catch ex As Exception
            ErrorMes.Text = "İşleminizde hata oluşmuştur lütfen tekrar deneyiniz."
        End Try
      
       





    End Sub
    Public Sub PrintSearch()
        Dim index As Integer
        Dim selecteditem As String = ""
        Dim count As Integer = 0
        Dim dtson As DataTable = New DataTable()
        Dim dt As DataTable = New DataTable()
        Dim control As Integer = 0
        Dim index2 As Integer




        Dim bilgiler() As String = TxtDate.Text.Split("/")
        Label26.Text = ""
        For Each satir As String In bilgiler
            Label26.Text += satir
        Next



        Dim bilgiler2() As String = TxtDate2.Text.Split("/")
        Label27.Text = ""
        For Each satir2 As String In bilgiler2
            Label27.Text += satir2
        Next

        For index = 0 To ListBox1.Items.Count - 1
            If ListBox1.Items(index).Selected Then
                'selecteditem += "'" + ListBox1.Items(index).Value.ToString() + "'"
                'count = count + 1
                control = ListBox1.Items(index).Value.ToString().IndexOf(",")

                If control <> -1 Then
                    Dim list() As String = ListBox1.Items(index).Value.ToString().Split(",")
                    For Each rownum As String In list
                        dt = New DataTable()
                        dt = Customer_History(Convert.ToInt32(LblCsid.Text), Label27.Text, Label26.Text, rownum)
                        dtson.Merge(dt)
                    Next

                Else
                    dt = New DataTable()
                    dt = Customer_History(Convert.ToInt32(LblCsid.Text), Label27.Text, Label26.Text, ListBox1.Items(index).Value.ToString())
                    dtson.Merge(dt)
                End If


                'Response.Write("Customer_History(" + Convert.ToInt32(LblCsid.Text).ToString() + "," + Label27.Text + "," + Label26.Text + "," + ListBox1.Items(index).Value.ToString())



            End If

        Next

        'Dim dt2 As DataTable = dt
        'dt2.Merge(dt)


        ' Response.Write(dt.Rows(0)(0).ToString)

        If dtson.Rows.Count > 0 Then
            emtytable.Visible = False
            GridView2.Visible = True
            GridView2.DataSource = dtson
            GridView2.DataBind()

        Else
            emtytable.Visible = True
            GridView2.Visible = False
        End If
    End Sub

    Protected Sub SCustCode1_Click(sender As Object, e As EventArgs) Handles SCustCode1.Click
        Dim clear2 As DataTable = New DataTable
        GridView2.DataSource = clear2
        GridView2.DataBind()
        emtytable.Visible = True
        ListBox1.SelectedIndex = -1

    End Sub
    Public Sub clear()
        LblCsid.Text = ""
        LblCustcodeMSısdn.Text = ""
        LblCustomer.Text = ""
        GridView2.DataSource = Nothing
        GridView2.DataBind()
        confirmTable.Visible = False
        ListBox1.SelectedIndex = -1
    End Sub


    Protected Sub GridView2_PageIndexChanging(sender As Object, e As GridViewPageEventArgs) Handles GridView2.PageIndexChanging
        GridView2.PageIndex = e.NewPageIndex
        If lblcontrol.Text = "0" Then
            Dim dthist As DataTable = ContractHistoryAuto(Convert.ToInt32(LblCsid.Text), Label27.Text, Label26.Text)
            If dthist.Rows.Count > 0 Then
                emtytable.Visible = False
                GridView2.Visible = True
                GridView2.DataSource = dthist
                GridView2.DataBind()

            Else
                emtytable.Visible = True
                GridView2.Visible = False
            End If
        Else
            PrintSearch()
        End If


    End Sub
End Class